/**
 * Created by python on 19-2-28.
 */



let  app = new Vue({
    el:"#app",
    data:{
        // 页面中需要使用到的数据，键值对
        act : null,
        now_second : 0,
        deadline_second : 0,
        last_time : 0

    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        let  activity_id = get_query_string("id" , 1);
        console.log(activity_id);
        axios.get (HOST + "/activities/" + activity_id)
            .then(response=>{
                this.act = response.data
            //    获取当前时间  获取截止时间
                let server_lime = response.headers.date;
                console.log('server_time = ' + server_lime)
                this.now_second = Math.floor(new  Date(server_lime).getTime() /1000);


                this.now_second = Math.floor(new  Date().getTime() /1000);
                this.deadline_second = Math.floor( new Date(response.data.deadline ).getTime() /1000);

            //    通过定时器  让当前时间流逝
                setInterval( ()=>{
                    this.now_second += 1 ;
                    this.last_time = this.deadline_second - this.now_second;
                    },1000

                )

            //    显示两个时间差 作为倒计时

            });
    },
    methods:{
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
    },
    computed:{
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    },

    filters:{
        second2dhms:function (value) {
            let day =  Math.floor(value / (60 * 60 * 24));
            let hour =  Math.floor(value % (60 * 60 * 24) / (60 * 60));
            let minute = Math.floor(value % (60*60) / 60);
            let second = value % 60  ;
            return day + "天" + hour + " 时" + minute + "分" + second + " 秒"

        }
    }

});




